package com.sakura.taos.tool.manipulator.conf;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import com.sakura.taos.tool.manipulator.dialects.TaosDataDialect;
import com.sakura.taos.tool.manipulator.dialects.TaosPaginationInnerInterceptor;
import com.sakura.taos.tool.manipulator.tool.CustomIdGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 贺坤
 * @Date: 2021/1/26 9:46
 */
@Configuration
public class MybatisPlusConf {
    /**
     * 分页拦截器
     * @return
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // mybatis-plus 暂时没有集成 taos,所以根据taos官方示例,实现分页方言
        TaosDataDialect dataDialect = new TaosDataDialect();
//         mybatis-plus 没集成taos,对涛思的分页返回出现兼容问题,重写有问题的方法, 以向官方返回兼容问题,后续升级删除
        PaginationInnerInterceptor taosPaginationInnerInterceptor = new TaosPaginationInnerInterceptor(dataDialect);
        interceptor.addInnerInterceptor(taosPaginationInnerInterceptor);
        return interceptor;
    }

    /**
     * ID 生成器
     * @return
     */
    @Bean
    public IdentifierGenerator idGenerator() {
        return new CustomIdGenerator();
    }
}
